﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Utilities/Table</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
			<h4 class="menu-item"><a href="#Table">Table</a></h4>
			<div class="menu-item"><a href="#"></a></div>
			<div class="menu-item"><a href="#Table:set">set</a></div>
			<div class="menu-item"><a href="#Table:get">get</a></div>
			<div class="menu-item"><a href="#Table:erase">erase</a></div>
			<div class="menu-item"><a href="#Table:each">each</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="Table"><a href="#Table">Class: Table</a></h1>

<p class="description">A LUA-style table implementation that allows for arbitrary data types for keys.</p>

<h3>Note</h3>

<ul>
<li>Table should only be used when it's really important to use non-scalar types as keys, otherwise use plain objects, which have a better performance.</li>
</ul>
<h2><a href="#">Table Method: constructor</a></h2>

<h3 class="description">Syntax</h3>

<pre class="javascript"><span class="kw2">var</span> myTable = <span class="kw2">new</span> Table<span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<p>None</p>

<h3>Returns</h3>

<ul>
<li>(<em>object</em>) A new Table instance.</li>
</ul>
<h2 id="Table:set"><a href="#Table:set">Table Method: set</a></h2>

<p class="description">Set a value for a specific key. Note that the key can be anything - a function, an object, an element, etc.</p>

<h3>Syntax</h3>

<pre class="javascript">myTable.<span class="me1">set</span><span class="br0">(</span>key, value<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>key - (<em>object</em>) The key for the value; any type of object.</li>
<li>value  - (<em>object</em>) The value for the key; any type of object.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>object</em>) This Table instance.</li>
</ul>
<h3>Examples</h3>

<pre class="javascript"><span class="kw2">var</span> myTable = <span class="kw2">new</span> Table<span class="br0">(</span><span class="br0">)</span>;
myTable.<span class="me1">set</span><span class="br0">(</span>$<span class="br0">(</span><span class="st0">'myForm'</span><span class="br0">)</span>, <span class="br0">{</span>foo: <span class="st0">'bar'</span><span class="br0">}</span><span class="br0">)</span>;
myTable.<span class="me1">set</span><span class="br0">(</span>myClassInstance, $$<span class="br0">(</span><span class="st0">'.someElements'</span><span class="br0">)</span><span class="br0">)</span>;
</pre>

<h2 id="Table:get"><a href="#Table:get">Table Method: get</a></h2>

<p class="description">Get a value for a specific key.</p>

<h3>Syntax</h3>

<pre class="javascript">myTable.<span class="me1">get</span><span class="br0">(</span>key<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>key - (<em>object</em>) The key for the value.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>object</em>) the value set for the specified key.</li>
</ul>
<h2 id="Table:erase"><a href="#Table:erase">Table Method: set</a></h2>

<p class="description">Erase a given key/value from the Table instance.</p>

<h3>Syntax</h3>

<pre class="javascript">myTable.<span class="me1">erase</span><span class="br0">(</span>key<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>key - (<em>object</em>) The key for the value.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>object</em>) This Table instance.</li>
</ul>
<h2 id="Table:each"><a href="#Table:each">Table Method: each</a></h2>

<p class="description">Iterates over the key/values in the table.</p>

<h3>Syntax</h3>

<pre class="javascript">myTable.<span class="me1">each</span><span class="br0">(</span><span class="kw2">function</span>, bind<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>function - (<em>function</em>) Function executed for each key/value pair in the Table instance; passed two arguments (key and value).</li>
<li>bind - (<em>object</em>, optional) The object to be used as 'this' in the function. For more information see <a href="../../core/Types/Function.html#Function:bind">Function:bind</a>.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>object</em>) This Table instance.</li>
</ul>
<h3>Examples</h3>

<pre class="javascript"><span class="kw2">var</span> myTable = <span class="kw2">new</span> Table<span class="br0">(</span><span class="br0">)</span>;
<span class="co1">// first set some values</span>
myTable.<span class="me1">set</span><span class="br0">(</span>$<span class="br0">(</span><span class="st0">'myForm'</span><span class="br0">)</span>, <span class="br0">{</span>foo: <span class="st0">'bar'</span><span class="br0">}</span><span class="br0">)</span>;
myTable.<span class="me1">set</span><span class="br0">(</span>myClassInstance, $$<span class="br0">(</span><span class="st0">'.someElements'</span><span class="br0">)</span><span class="br0">)</span>;
<span class="co1">// and now iterate over them</span>
myTable.<span class="me1">each</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span>value, key<span class="br0">)</span><span class="br0">{</span>
    console.<span class="me1">log</span><span class="br0">(</span>value, key<span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>;
</pre>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
